#!/bin/bash
# ============================================
# 复制数据到 Hive 容器脚本
# 用途：将本地数据复制到 Hive 容器中
# ============================================

# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color

CONTAINER_NAME="hive_cmcc"

echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN}复制数据到 Hive 容器${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""

# 检查容器是否运行
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
    echo -e "${RED}错误：容器 ${CONTAINER_NAME} 未运行${NC}"
    echo "请先运行 ./start_hive.sh 启动容器"
    exit 1
fi

# 复制 output_data 目录到容器
echo "正在复制 output_data 目录到容器..."
if docker cp output_data ${CONTAINER_NAME}:/opt/hive/; then
    echo -e "${GREEN}✓ output_data 目录复制成功${NC}"
else
    echo -e "${RED}✗ output_data 目录复制失败${NC}"
    exit 1
fi

echo ""
echo -e "${GREEN}============================================${NC}"
echo -e "${GREEN}数据复制完成！${NC}"
echo -e "${GREEN}============================================${NC}"
echo ""
echo "容器内数据路径："
echo "  /opt/hive/output_data/"
echo ""
echo "验证数据："
echo "  docker exec ${CONTAINER_NAME} ls -la /opt/hive/output_data/"
echo ""
echo "现在可以执行导入命令："
echo "  beeline -u \"jdbc:hive2://localhost:10000\" -f import_hive_data.sql"
